define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'affair/index' + location.search,
                    add_url: 'affair/add',
                    edit_url: 'affair/edit',
                    del_url: 'affair/del',
                    multi_url: 'affair/multi',
                    import_url: 'affair/import',
                    table: 'affair',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'desc', title: __('Desc'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'yongtu.name', title: __('Yongtu.name'), operate: 'LIKE'},
                        
						{
							field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
								{
									name: 'files',
									title: '要素信息',
									text: '要素信息',
									icon: 'fa fa-list',
									 
									classname: 'btn btn-xs btn-primary btn-dialog',
									url: 'yaosu/index',
									click: function (e, data) {
										console.log(e)
										console.log(data)
										//$("#myTabContent2 .form-commonsearch input[name='username']").val(data.username);
										//$("#myTabContent2 .btn-refresh").trigger("click");
									}
								},
								{
									name: 'files',
									title: '附件设置',
									text: '附件设置',
									icon: 'fa fa-list',
									 
									classname: 'btn btn-xs btn-primary btn-dialog',
									url: 'casefile/index',
									click: function (e, data) {
										console.log(e)
										console.log(data)
										//$("#myTabContent2 .form-commonsearch input[name='username']").val(data.username);
										//$("#myTabContent2 .btn-refresh").trigger("click");
									}
								}
							], formatter: Table.api.formatter.operate
						}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'affair/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'affair/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'affair/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
